from pydantic import BaseModel, Field, validator
from typing import List


class MapInfoSettings(BaseModel):
    time_delta: str = Field(..., regex='(一天)|(一周)|(一月)')


class RenterMarkSettings(BaseModel):
    is_pos_seq: bool = Field(True, title='是否正序')
    topN: int


class UserFeedbackSettings(BaseModel):
    topN: int


class ViolationShowSettings(BaseModel):
    types: List[str] = Field(..., title='违章信息展示的类型', description='列表中的字符串来自于 `/violation-types` 接口的返回数据')
    topN: int = Field(..., title='按照记录的创建时间来排名的 topN')


class ViolationRankSettings(BaseModel):
    topN: int = Field(..., title='按照罚款金额的排名的 topN')


class ComplaintTendency(BaseModel):
    time_span: str = Field(..., regex='(一天)|(一周)|(一月)')
    states: List[int] = Field(..., title='用户所选择的状态列表', description='这些参数来自于 `/complaint-deal-states` 接口返回的 key, 呈现在大屏中将只有所选中的这些状态的投诉记录')

    @validator('states')
    def validate_states(cls, v: List[int]):
        for state in v:
            if not 0 <= state <= 3:
                raise ValueError('state 必须是 0~3')
        return v


class ComplaintShow(BaseModel):
    topN: int = Field(..., title='按照投诉的 update time 来排序的 topN')
